﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LGE;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace UpUp
{
    public class SnowFlake : LGE.Effect
    {
        Vector2 speed;
        public static Texture2D sprite = null;
        float rotation;
        float scale;
        Color color;

        public SnowFlake(bool isBack)
            : base(new Vector2(GameObject.relativeObject.position.X + Rand.Next(0, 3000), GameObject.relativeObject.position.Y - Rand.Next(800, 1000)))
        {
            if (sprite == null) sprite = Engine.Load<Texture2D>("Images\\Effects\\snowflake");
            speed = new Vector2(-Rand.Next(1, 4), Rand.Next(1, 4));
            rotation = Rand.NextFloat(0, MathHelper.TwoPi);
            
            scale = Rand.NextFloat(.5f, .7f);
            if (isBack) scale -= .3f;

            float a = Rand.NextFloat(.5f, 1f);
            if (isBack) a -= .3f;
            color = new Color(a, a, a, a);
        }

        public override void Update(GameTime gameTime)
        {
            if (position.X < GameObject.relativeObject.position.X - 2000 || position.Y > GameObject.relativeObject.position.Y + 2000) Die();
            position += speed;
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            Vector2 drawPosition = position - GameObject.relativeObject.position + GameObject.relativeObject.drawPosition;
            spriteBatch.Draw(sprite, drawPosition, null, color, rotation, Vector2.Zero, scale, SpriteEffects.None, 0);
        }
    }
}